package work.parabola.keyboardswitch.pojo.query.keyboard;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import work.parabola.keyboardswitch.common.PlateConst;
import work.parabola.keyboardswitch.common.ServerResponse;

@Data
@ToString
@EqualsAndHashCode
public class KeyboardAddQuery {

    private String name;

    private Integer type;

    private Boolean open;

    public ServerResponse validate() {
        if (StringUtils.isBlank(this.name)) {
            return ServerResponse.createByErrorMessage("名称不能为空");
        }
        if (type == null) {
            return ServerResponse.createByErrorMessage("键盘配列未选择");
        }
        if(PlateConst.PlateTypeEnum.codeOf(this.type) == null){
            return ServerResponse.createByErrorMessage("键盘配列选择错误");
        }
        if(this.open == null){
            this.open = false;
        }
        return ServerResponse.createBySuccess();
    }
}
